package com.atguigu.practice;

import java.util.ArrayList;
import java.util.List;

public class subsets {
    public static void process(int[] nums,int i,List<Integer> list,List<List<Integer>> res){
        if(i==nums.length){
            res.add(list);
            return;
        }else{
            List<Integer> resKeep=copyList(list);
            resKeep.add(nums[i]);
            process(nums,i+1,resKeep,res); //要当前字符的路
            List<Integer> resNoInclude=copyList(list);
            process(nums,i+1,resNoInclude,res); //不要当前字符的路
        }
    }

    public static List<Integer> copyList(List<Integer> list){
        List<Integer> res=new ArrayList<>();
        for(int i=0;i<list.size();i++){
            res.add(list.get(i));
        }
        return res;
    }

    public List<List<Integer>> subset(int[] nums){
        List<List<Integer>> res=new ArrayList<>();
        process(nums,0,new ArrayList<>(),res);
        return res;
    }
}
